home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_01
/
1001096b
< prev
next >
Wrap
Text File
|
1991-11-23
|
587b
|
35 lines
Listing 5
//
// rational.cpp
//
#include "rational.h"
rational rational::operator+(rational r)
{
return rational(num * r.denom + r.num * denom,
denom * r.denom);
}
rational rational::operator-(rational r)
{
return rational(num * r.denom - r.num * denom,
denom * r.denom);
}
rational rational::operator*(rational r)
{
return rational(num * r.num, denom * r.denom);
}
rational rational::operator/(rational r)
{
return rational(num * r.denom, denom * r.num);
}
void rational::put(FILE *f)
{
fprintf(f, "(%ld/%ld)", num, denom);
}